package com.camel.iamhi.service.impl;

import com.camel.iamhi.model.SysUser;
import com.camel.iamhi.repository.UserRepository;
import com.camel.iamhi.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends AbstractBaseService<SysUser> implements UserService<SysUser> {

    @Resource
    private UserRepository userRepository;

    @Value("${app.passwd.default}")
    public String defaultPasswd;

    @Override
    JpaRepository<SysUser, Long> getRepository() {
        return userRepository;
    }

    @Override
    public SysUser resetPasswd(SysUser entity) {
        SysUser sysUser = userRepository.findById(entity.getId()).orElseThrow();
        sysUser.setPassword(defaultPasswd);
        return userRepository.save(sysUser);
    }
}
